package correct.day14;

import java.util.Scanner;

public class Test3 {
    static int N = (int)1e4 + 10;
    static int[] sum = new int[N]; // sum[i] 表⽰ i 这个数的总和
    static int[] f = new int[N];
    static int[] g = new int[N];
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int x = 0;
        for(int i = 0; i < n; i++)
        {
            x = in.nextInt();
            sum[x] += x;
        }
        for(int i = 1; i < N; i++)
        {
            f[i] = g[i - 1] + sum[i];
            g[i] = Math.max(g[i - 1], f[i - 1]);
        }
        System.out.println(Math.max(f[N - 1], g[N - 1]));
    }
}
